package com.example.blew.demo.uitl;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/9/6
 */

import com.example.blew.demo.config.ResultCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author YJ
 */
@Data
public class RrturnMesage {

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    //将类的构造方法改为私有
    private RrturnMesage(){}

    //成功的方法
    public static RrturnMesage ok(){
        RrturnMesage r = new RrturnMesage();
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    //失败的方法
    public static RrturnMesage error(){
        RrturnMesage r = new RrturnMesage();
        r.setCode(ResultCode.ERROR);
        r.setMessage("失败");
        return r;
    }

    //返回this，R的对象，可以进行链式编程
    public RrturnMesage success(Boolean success){
        return this;
    }

    public RrturnMesage message(String message){
        this.setMessage(message);
        return this;
    }

    public RrturnMesage code(Integer code){
        this.setCode(code);
        return this;
    }

    public RrturnMesage data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public RrturnMesage data(Map<String, Object> map){
        this.setData(map);
        return this;
    }


}